<?php

namespace App\Transformers\Web;

use App\Models\Category;
use League\Fractal\TransformerAbstract;

class IntegralTransformer extends TransformerAbstract
{
    public function transform($integral)
    {
        $total_integral = array_sum($integral->where('user_id',auth()->id())->pluck('this_integral')->toArray());

        return [
            'total_integral' => $total_integral,
            'this_integral' => $integral->this_integral,
            'type' => $integral->examination->type,
            'subject' => Category::query()->where('id',$integral->examination->subject_id)->pluck('name'),
            'get_time' => $integral->get_time
        ];
    }
}

